package esercizi_fondamenti;

public class OperazioniVettori2 {

	public static boolean verificaSommaK(int[]a, int[]b, int k){
		boolean verifica = false;
		for(int i=0; i<=a.length; i++)
			for(int j=0; j<b.length && !verifica; j++){
				if(a[i]+b[j]==k) verifica=true;
				else verifica=false;
		
		}
		return verifica;
	}//verificaSomma
	
	public static boolean verificaVettore(int[]a, int[]b){
		
			for(int i=0; i<=a.length; i++){
				boolean trovato=false;
				for(int j=0; j<b.length && !trovato; j++){
					if(a[i]==-b[j])  trovato=true;
				if(!trovato) return false;}
			}
		return true;
	}//verificaVettore
	
	public static int[] rimuoviMultipli(int[]a, int[]b){
		int cont=0;
		int[]temp=new int[cont];
			for(int j=0; j<b.length; j++){
				if(eMultiplo(a,b[j])) {
					temp[cont]=b[j];
						cont++;
				}
			}
			int[]ris=new int[cont];
			for(int i=0; i<cont; i++){
				ris[i]=temp[i];
			}
		return ris;
		}//rimuoviMultipli
	
	static boolean eMultiplo(int[]v, int x){
		boolean ok=false;
		int cont=0;
		while(!ok && cont<v.length){
			if(x%v[cont]!=0) 
				ok= true;
					cont++;
			
		}
		return ok;
	}//eMultiplo

	
	
	
	
	public static void main(String[] args) {
		
		int[]v1={2,9,8,4,12};
		int[]v2={7,10,13,33};
		int[]ris=rimuoviMultipli(v1,v2);
		for(int h=0; h<ris.length; h++){
			System.out.print(ris[h]+" ");
		}
		System.out.println();
		
		int[]lav={1,5,3,2};
		int[]mar={5,12,7,9,8,2};
		int k=10;
		System.out.println(verificaSommaK(lav,mar,k));
		System.out.println();
		int[]a={20,-9,4,-8};
		int[]b1={1,9,-20,4,-4,0,8};
		int[]b2={1,9,4,0,8};
		System.out.println("tra a e b1: "+verificaVettore(a,b1));
		System.out.println();
		System.out.println("tra a e b2: "+verificaVettore(a,b2));
		

	}

}
